package com.bw.medical.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.medical.dao.TbPatientDao;
import com.bw.medical.entity.TbDockerLevelEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bw.medical.entity.TbPatientEntity;
import com.bw.medical.service.TbPatientService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;



/**
 * 患者表 
 *
 * @author wj
 * @email sunlightcs@gmail.com
 * @date 2021-08-14 18:10:33
 */
@RestController
@RequestMapping("medical/tbpatient")
public class TbPatientController {
    @Autowired
    private TbPatientService tbPatientService;
    @Autowired
    private TbPatientDao tbPatientDao;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tbPatientService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 查询患者信息
     */
    @RequestMapping("/k2")
    public TbPatientEntity k2(@RequestParam("patientId") Integer patientId){
        TbPatientEntity userId1 = tbPatientDao.selectOne(new QueryWrapper<TbPatientEntity>().eq("patient_id", patientId));
        return userId1;
    }

    /**
     * 查询
     */
    @RequestMapping("/info")
    public R info(@PathVariable("patientId") Integer patientId){
		TbPatientEntity tbPatient = tbPatientService.getById(patientId);

        return R.ok().put("tbPatient", tbPatient);
    }
    /**
     * 查询患者
     */
    @RequestMapping("/infos")
    public TbPatientEntity infos(@RequestParam("patientId") Integer patientId){
        TbPatientEntity tbPatient = tbPatientService.getById(patientId);
        return tbPatient;
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbPatientEntity tbPatient){
		tbPatientService.save(tbPatient);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TbPatientEntity tbPatient){
		tbPatientService.updateById(tbPatient);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] patientIds){
		tbPatientService.removeByIds(Arrays.asList(patientIds));

        return R.ok();
    }

}
